package edu.jmu.flowmeter.controller;

import edu.jmu.flowmeter.domain.Data;
import edu.jmu.flowmeter.dto.AbstractBaseResult;
import edu.jmu.flowmeter.service.DataService;
import edu.jmu.flowmeter.web.AbstractBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author Wen
 */
@RestController
@RequestMapping(value = "data")
public class DataController extends AbstractBaseController<Data> {

    @Autowired
    private DataService dataService;

    @GetMapping(value = "getAll")
    public AbstractBaseResult getAllListData() {
        Data data = new Data();
        List<Data> list = dataService.all(data);
        return success(0, 0, list);
    }

    @PostMapping(value = "save")
    public void saveData(Data data) {
        Date date = new Date();
        data.setDataTime(date);
        dataService.save(data);
    }


}
